package com.shareyi.jdwork.tree;

import java.util.ArrayList;
import java.util.List;

public class TreeElement {

    private Long id;
    private Long parentId;
    private List<TreeElement> childList;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getParentId() {
        return parentId;
    }

    public void setParentId(Long parentId) {
        this.parentId = parentId;
    }

    public List<TreeElement> getChildList() {
        return childList;
    }

    public void setChildList(List<TreeElement> childList) {
        this.childList = childList;
    }

    @Override
    public String toString() {
        return "TreeElement{" +
                "id=" + id +
                ", parentId=" + parentId +
                ", childList=" + childList +
                '}';
    }

    public void addChild(TreeElement treeElement) {
        if(childList==null){
            childList=new ArrayList<TreeElement>();
        }
        if(childList.contains(treeElement)){
            return;
        }
        childList.add(treeElement);
    }
}
